package com.richapp.launcher.ui.activities;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

import com.key.virtual.ir.InputKeyValueJni;
import com.richapp.launcher.R;
import com.richapp.launcher.receiver.LauncherMessageReceiver;
import com.richapp.launcher.ui.view.TabPageIndicator;

import java.util.Date;
import java.util.concurrent.TimeUnit;

public class ScreenSaverAdvActivity extends Activity {

    public static volatile boolean finished = false;

    private TimeUnit timeUnit = TimeUnit.MINUTES;
    private long sleepTime = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        finished = false;
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  //设置全屏

        setContentView(R.layout.activity_screen_saver_adv);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    long startTime = new Date().getTime();
                    while (!finished && startTime + timeUnit.toMillis(sleepTime) >= new Date().getTime()) {
                        timeUnit.sleep(1);
                    }
                    if (startTime + timeUnit.toMillis(sleepTime) >= new Date().getTime()) {
                        ScreenSaverAdvActivity.this.finish();
                        return;
                    }
                    ScreenSaverAdvActivity.this.finish();
                } catch (InterruptedException e) {
                    Log.e(ScreenSaverAdvActivity.class.getName(), e.getMessage(), e);
                }
            }

        }).start();

    }

    @Override
    public void finish() {
        ScreenSaverAdvActivity.finished = true;
        super.finish();
    }
}
